package com.db.williamchart.renderer.executor;

import com.db.williamchart.extensions.Pair;

import com.db.williamchart.data.Frame;

import java.util.ArrayList;
import java.util.List;

public class DefineHorizontalBarsClickableFrames {

    public List<Frame> invoke(
            Frame innerFrame,
            List<Pair<Float, Float>> datapointsCoordinates
    ) {
        float halfDistanceBetweenDataPoints =
                (innerFrame.getBottom() - innerFrame.getTop() - (datapointsCoordinates.size() + 1)) /
                        datapointsCoordinates.size() / 2;
        List<Frame> list = new ArrayList<>();
        for (Pair<Float, Float> pair : datapointsCoordinates) {
            Frame frame = new Frame(
                    innerFrame.getLeft(),
                    pair.second - halfDistanceBetweenDataPoints,
                    innerFrame.getRight(),
                    pair.second + halfDistanceBetweenDataPoints
            );
            list.add(frame);
        }
        return list;
    }
}
